﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twitter;

namespace FriendsNearbyBot
{
	internal class HelpProcessor : IMessageProcessor
	{
        IMessageBuilder messageBuilder;

        public HelpProcessor() : this(new ListMessageBuilder())
        {
        }

        public HelpProcessor(IMessageBuilder messageBuilder)
        {
            this.messageBuilder = messageBuilder;
        }

        public bool CanProcess(Message message)
        {
            return message.Text == "?" || message.Text == "help";
        }

		public RunNextProcessor Process(IBotClient client, Message message)
		{
            if (CanProcess(message))
            {
                // Split String Resource in lines
                messageBuilder.Clear();
                foreach (var lineOfHelp in Properties.Resources.HelpMessage.Split('\n'))
                {
                    messageBuilder.AppendFragment(lineOfHelp + "\n");
                }

                // Send help to user SMS.
                client.SendMessages(message.Sender.ScreenName, messageBuilder.GetMessages(), message, this.GetType().Name);

                BotProcessor.MessageProcessed(client, message);

                return RunNextProcessor.No;
            }
            else
            {
                return RunNextProcessor.Yes;
            }
		}
	}
}
